package yue.shen.android.demo.select

import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.RequestOptions
import com.luck.picture.lib.entity.LocalMedia
import com.luck.picture.lib.tools.DateUtils
import yue.shen.android.demo.R

class SelectVideoViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

    private val imageView = itemView.findViewById<ImageView>(R.id.image_view)
    private val notSelect = itemView.findViewById<ImageView>(R.id.image_select_n)
    private val select = itemView.findViewById<TextView>(R.id.tv_select)
    private val duration = itemView.findViewById<TextView>(R.id.tv_duration)

    fun bindData(item: LocalMedia) {
        val options = RequestOptions().override(180, 180).diskCacheStrategy(DiskCacheStrategy.ALL)
            .centerCrop().placeholder(R.drawable.image_placeholder)
        Glide.with(itemView.context)
            .asBitmap()
            .load(item.path)
            .apply(options)
            .into(imageView)
        if (item.num > 0) {
            notSelect.visibility = View.GONE
            select.visibility = View.VISIBLE
            select.text = "${item.num}"
        } else {
            notSelect.visibility = View.VISIBLE
            select.visibility = View.GONE
            select.text = ""
        }
        duration.text = DateUtils.timeParse(item.duration)
    }


    fun getImageView(): ImageView = imageView

    fun getNotSelectView(): ImageView = notSelect

    fun getSelectView(): TextView = select

    fun setNotSelectClick(listener: View.OnClickListener) {
        notSelect.setOnClickListener(listener)
    }

    fun setSelectClick(listener: View.OnClickListener) {
        select.setOnClickListener(listener)
    }

}